package maquina.interfaz.io.impl;



import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

import javax.swing.JPanel;

import maquina.gestor.flujo.GestorFlujo;
import maquina.interfaz.io.PerifericoEntrada;

public class Teclado extends PerifericoEntrada implements SwingHandler,KeyListener {

	public Teclado(GestorFlujo gestor) {

		super.setGestorDeVoto(gestor);
	}

	public void keyReleased(KeyEvent e) {
	}

	public void keyTyped(KeyEvent e) {
	}

	public void keyPressed(KeyEvent e) {
		
		int key = e.getKeyCode();
		
		switch (key) {
		
		case KeyEvent.VK_1:
			super.gestorVoto.gestionarEntrada(new Integer(1));
			break;
		case KeyEvent.VK_2:// 2
			super.gestorVoto.gestionarEntrada(new Integer(2));
			break;
		case KeyEvent.VK_3:// 3
			super.gestorVoto.gestionarEntrada(new Integer(3));
			break;
		case KeyEvent.VK_4:
			super.gestorVoto.gestionarEntrada(new Integer(4));
			break;
		case KeyEvent.VK_5:
			super.gestorVoto.gestionarEntrada(new Integer(5));
			break;
		case KeyEvent.VK_6:
			super.gestorVoto.gestionarEntrada(new Integer(6));
			break;
		case KeyEvent.VK_7:
			super.gestorVoto.gestionarEntrada(new Integer(7));
			break;
		case KeyEvent.VK_8:
			super.gestorVoto.gestionarEntrada(new Integer(8));
			break;
		case KeyEvent.VK_9:
			super.gestorVoto.gestionarEntrada(new Integer(9));
			break;
		case KeyEvent.VK_ENTER:// ENTER(confirma seleccion)
			super.gestorVoto.gestionarConfirmacionSeleccion();
			break;
		}
	}

	public void addListener(JPanel panel) {

		panel.addKeyListener(this);
	}
}
